package model

import (
	"io"
	"net/http"
	"strings"
)

var ports []string

func OpenPort() {
	ports = strings.Split(testOpenPort, ",")
	for _, v := range ports {
		go func(port string) {
			mux := http.NewServeMux()
			mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
				w.Header().Set("remoteIp", GetIntranetIp())
				io.WriteString(w, "Port: "+port+" is Open")
				return
			})
			err := http.ListenAndServe(":"+port, mux)
			if err != nil {
				Log.Println("Open port err: ", port, err)
			}
		}(v)
	}
	select {}
}
